package br.com.infnet.cultbook.repository.dao.impl;

import javax.ejb.Stateless;
import javax.persistence.NoResultException;
import javax.persistence.Query;

import br.com.infnet.cultbook.domain.profile.Pessoa;
import br.com.infnet.cultbook.repository.dao.PessoaDAO;
import br.com.infnet.cultbook.repository.dao.common.impl.BaseDAOImpl;

@Stateless
public final class PessoaDAOImpl extends BaseDAOImpl<Pessoa> implements PessoaDAO {

	
	@Override
	public Pessoa findByLoginAndSenha(String login, String senha) {
		Query query = manager.createQuery("from Pessoa p where p.login = :login and senha = :senha");
		query.setParameter("login", login);
		query.setParameter("senha", senha);
		
		try {
			return (Pessoa) query.getSingleResult();
		} catch(NoResultException npe) {
			return null;
		}
	}

}
